//
//  segTarget_TabBars.m
//  SEGStandard
//
//  Created by 山刘 on 2019/4/16.
//  Copyright © 2019年 山刘. All rights reserved.
//

#import "SEGTarget_TabBars.h"
#import "SEGBasicTabBarController.h"
#import "SEGMenulist2Manager.h"


@implementation SEGTarget_TabBars
/**
 * 跳转到主界面
 * @author Sam
 */
-(void)segAction_pushToMainViewController:(NSDictionary*)params{
    UIViewController *tab = [SEGBasicTabBarController new];
    [UIApplication sharedApplication].delegate.window.rootViewController = tab;
    [UIView transitionWithView:[UIApplication sharedApplication].delegate.window duration:0.3 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
        [UIApplication sharedApplication].delegate.window.rootViewController = tab;
    } completion:nil];
    [[SEGUhomeMediator sharedInstance] seg_submitJpushToken:nil];
}

/**
 * 控制纷享刷新控件的展示和隐藏
 * @author Sam
 */
//-(void)segAction_frshItemShow:(NSDictionary*)params{
//    SEGBasicTabBarController * app = (SEGBasicTabBarController *)[UIApplication sharedApplication].delegate.window.rootViewController;
//    if([app respondsToSelector:@selector(segShowFreshImage:)]){
//        [app segShowFreshImage:[[params valueForKey:@"isShow"] boolValue]];
//    }
//}

/**
 * 跳转到指定Tab项
 * @author Sam
 */
-(void)segAction_selctedToTabParams:(NSDictionary*)params{
    SEGBasicTabBarController * app = (SEGBasicTabBarController *)[UIApplication sharedApplication].delegate.window.rootViewController;
    if([app respondsToSelector:@selector(segSelectedTab:)]){
        [app segSelectedTab:[params valueForKey:@"action"]];
    }
}

/**
 * 跳转开门界面
 * @author Sam
 */
-(void)segAction_showOpenDoorView:(NSDictionary*)params{
    SEGBasicTabBarController * app = (SEGBasicTabBarController *)[UIApplication sharedApplication].delegate.window.rootViewController;
    if([app respondsToSelector:@selector(clickComposeButton)]){
        [app clickComposeButton];
    }
}

/**
 * 自动跳转到指定Tab项，有则跳tab，没有则跳一个新的页面
 * @author Sam
 */
-(void)segAction_autoSelctedToTabParams:(NSDictionary*)params {
    __block BOOL isTab = NO;
    [[SEGMenulist2Manager sharedManager].menuListTab enumerateObjectsUsingBlock:^(SEGMenuListModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if ([obj.action isEqualToString:[params valueForKey:@"action"]]) {
            isTab = YES;
            *stop = YES;
        }
    }];
    //是否存在tab
    if (isTab) {
        SEGBasicTabBarController * app = (SEGBasicTabBarController *)[UIApplication sharedApplication].delegate.window.rootViewController;
        if([app respondsToSelector:@selector(segSelectedTab:)]){
            [app segSelectedTab:[params valueForKey:@"action"]];
        }
    }else {
        if ([[params valueForKey:@"action"] isEqualToString:@"TAB_MESSAGE"]) {
            UIViewController* curentVC = [[SEGUhomeMediator sharedInstance]seg_getCurrentController:nil];
            UIViewController *vc = [[SEGUhomeMediator sharedInstance] seg_initMessageRootViewController:nil];
            [curentVC.navigationController pushViewController:vc animated:YES];
        }else {
            //TODO 其他类型
        }
        
    }
    
    
    
}

@end
